package Server;

import java.io.File;
import java.util.List;

public class Filter {
	private static final String IDcard_regex = 
			"[1-9]\\d{5}[1-9]\\d{3}((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])\\d{3}([0-9]|X)"; 
	
	private static final String mobiletel_regex = 
			"((13[0-9])|(15[^4,\\D])|(18[0-9]))\\d{8}";
	
	//区号-号码（3位区号-8位号码和4位区号）
	private static final String tel_regex = 
			"(\\(?(010|021|022|023|024|025|026|027|028|029|852)?\\)?-?\\d{8})|(\\(?(0[3-9][0-9]{2})?\\)?-?\\d{7,8})";
	
	//区号-号码-分机号（3位区号-8位号码和4位区号）
	private static final String _tel_regex =
			"(\\(?(010|021|022|023|024|025|026|027|028|029|852|)\\)?-?\\d{8}(\\-?[0-9]{1,4})?)|(\\(?(0[3-9][0-9]{2})\\)?-?\\d{7,8}(\\-?[0-9]{1,4})?)";
	
	//身份证过滤
	private String filte_IDcard(String s){
		return s.replaceAll(IDcard_regex, "*");
	}
	
	//电话号码过滤
	private String filte_tel(String s){
		s = s.replaceAll(mobiletel_regex, "*");
		s = s.replaceAll(tel_regex, "*");
		s = s.replaceAll(_tel_regex, "*");
		return s;
	}

	String filte(String s){
		s = filte_IDcard(s);
		s = filte_tel(s);
		return s;
	}
	public static String getNewJob(String job,String rulepath,String encodepath){
		List<String> rule = IOHandler.readAsList(new File(rulepath));
		List<String> encodelist = IOHandler.readAsList(new File(encodepath));
		String line;
		String classname;
		for(int i = 0;i<encodelist.size();i++){
			line = encodelist.get(i);
			classname = "\\[\\[\\["+line.split("\t")[7];
			job = job.replaceAll(classname, "");
		}
		for(int i = 1;i<rule.size();i++){
			job = job.replaceAll(rule.get(i),"");
		}
		
		return job;
	}
	
	public static void main(String[] args) {
		Filter filter = new Filter();
		String str = "jiud18167103668集合地阿芳";
		str = filter.filte_tel(str);
		System.out.println(str);
	}
}
